import java.awt.Toolkit;
import java.util.Collections;
import java.util.Stack;
import javax.swing.ImageIcon;

public class Deck
{
	/**
	 * Stack that takes a Card
	 */

	Stack<Card> card = new Stack<Card>();

	/**
	 * Default constructor that makes each card. This constructor also shuffles
	 * the card
	 * 
	 * @see Card
	 * @see Collections
	 */
	public Deck()
	{
		card.add(new Card(1, 1, "yellow", makeIcon("y1.png")));
		card.add(new Card(2, 2, "yellow", makeIcon("y2.png")));
		card.add(new Card(3, 3, "yellow", makeIcon("y3.png")));
		card.add(new Card(4, 4, "yellow", makeIcon("y4.png")));
		card.add(new Card(5, 5, "yellow", makeIcon("y5.png")));
		card.add(new Card(6, 6, "yellow", makeIcon("y6.png")));
		card.add(new Card(7, 7, "yellow", makeIcon("y7.png")));
		card.add(new Card(8, 8, "yellow", makeIcon("y8.png")));
		card.add(new Card(9, 9, "yellow", makeIcon("y9.png")));
		card.add(new Card(10, 20, "yellow", makeIcon("yr.png")));
		card.add(new Card(11, 20, "yellow", makeIcon("ys.png")));
		card.add(new Card(12, 20, "yellow", makeIcon("yd2.png")));
		card.add(new Card(1, 1, "yellow", makeIcon("y1.png")));
		card.add(new Card(2, 2, "yellow", makeIcon("y2.png")));
		card.add(new Card(3, 3, "yellow", makeIcon("y3.png")));
		card.add(new Card(4, 4, "yellow", makeIcon("y4.png")));
		card.add(new Card(5, 5, "yellow", makeIcon("y5.png")));
		card.add(new Card(6, 6, "yellow", makeIcon("y6.png")));
		card.add(new Card(7, 7, "yellow", makeIcon("y7.png")));
		card.add(new Card(8, 8, "yellow", makeIcon("y8.png")));
		card.add(new Card(9, 9, "yellow", makeIcon("y9.png")));
		card.add(new Card(10, 20, "yellow", makeIcon("yr.png")));
		card.add(new Card(11, 20, "yellow", makeIcon("ys.png")));
		card.add(new Card(12, 20, "yellow", makeIcon("yd2.png")));
		card.add(new Card(0, 0, "yellow", makeIcon("y0.png")));
		card.add(new Card(1, 1, "red", makeIcon("r1.png")));
		card.add(new Card(2, 2, "red", makeIcon("r2.png")));
		card.add(new Card(3, 3, "red", makeIcon("r3.png")));
		card.add(new Card(4, 4, "red", makeIcon("r4.png")));
		card.add(new Card(5, 5, "red", makeIcon("r5.png")));
		card.add(new Card(6, 6, "red", makeIcon("r6.png")));
		card.add(new Card(7, 7, "red", makeIcon("r7.png")));
		card.add(new Card(8, 8, "red", makeIcon("r8.png")));
		card.add(new Card(9, 9, "red", makeIcon("r9.png")));
		card.add(new Card(10, 20, "red", makeIcon("rr.png")));
		card.add(new Card(11, 20, "red", makeIcon("rs.png")));
		card.add(new Card(12, 20, "red", makeIcon("rd2.png")));
		card.add(new Card(1, 1, "red", makeIcon("r1.png")));
		card.add(new Card(2, 2, "red", makeIcon("r2.png")));
		card.add(new Card(3, 3, "red", makeIcon("r3.png")));
		card.add(new Card(4, 4, "red", makeIcon("r4.png")));
		card.add(new Card(5, 5, "red", makeIcon("r5.png")));
		card.add(new Card(6, 6, "red", makeIcon("r6.png")));
		card.add(new Card(7, 7, "red", makeIcon("r7.png")));
		card.add(new Card(8, 8, "red", makeIcon("r8.png")));
		card.add(new Card(9, 9, "red", makeIcon("r9.png")));
		card.add(new Card(10, 20, "red", makeIcon("rr.png")));
		card.add(new Card(11, 20, "red", makeIcon("rs.png")));
		card.add(new Card(12, 20, "red", makeIcon("rd2.png")));
		card.add(new Card(0, 0, "red", makeIcon("r0.png")));
		card.add(new Card(1, 1, "green", makeIcon("g1.png")));
		card.add(new Card(2, 2, "green", makeIcon("g2.png")));
		card.add(new Card(3, 3, "green", makeIcon("g3.png")));
		card.add(new Card(4, 4, "green", makeIcon("g4.png")));
		card.add(new Card(5, 5, "green", makeIcon("g5.png")));
		card.add(new Card(6, 6, "green", makeIcon("g6.png")));
		card.add(new Card(7, 7, "green", makeIcon("g7.png")));
		card.add(new Card(8, 8, "green", makeIcon("g8.png")));
		card.add(new Card(9, 9, "green", makeIcon("g9.png")));
		card.add(new Card(10, 20, "green", makeIcon("gr.png")));
		card.add(new Card(11, 20, "green", makeIcon("gs.png")));
		card.add(new Card(12, 20, "green", makeIcon("gd2.png")));
		card.add(new Card(1, 1, "green", makeIcon("g1.png")));
		card.add(new Card(2, 2, "green", makeIcon("g2.png")));
		card.add(new Card(3, 3, "green", makeIcon("g3.png")));
		card.add(new Card(4, 4, "green", makeIcon("g4.png")));
		card.add(new Card(5, 5, "green", makeIcon("g5.png")));
		card.add(new Card(6, 6, "green", makeIcon("g6.png")));
		card.add(new Card(7, 7, "green", makeIcon("g7.png")));
		card.add(new Card(8, 8, "green", makeIcon("g8.png")));
		card.add(new Card(9, 9, "green", makeIcon("g9.png")));
		card.add(new Card(10, 20, "green", makeIcon("gr.png")));
		card.add(new Card(11, 20, "green", makeIcon("gs.png")));
		card.add(new Card(12, 20, "green", makeIcon("gd2.png")));
		card.add(new Card(0, 0, "green", makeIcon("g0.png")));
		card.add(new Card(1, 1, "blue", makeIcon("b1.png")));
		card.add(new Card(2, 2, "blue", makeIcon("b2.png")));
		card.add(new Card(3, 3, "blue", makeIcon("b3.png")));
		card.add(new Card(4, 4, "blue", makeIcon("b4.png")));
		card.add(new Card(5, 5, "blue", makeIcon("b5.png")));
		card.add(new Card(6, 6, "blue", makeIcon("b6.png")));
		card.add(new Card(7, 7, "blue", makeIcon("b7.png")));
		card.add(new Card(8, 8, "blue", makeIcon("b8.png")));
		card.add(new Card(9, 9, "blue", makeIcon("b9.png")));
		card.add(new Card(10, 20, "blue", makeIcon("br.png")));
		card.add(new Card(11, 20, "blue", makeIcon("bs.png")));
		card.add(new Card(12, 20, "blue", makeIcon("bd2.png")));
		card.add(new Card(1, 1, "blue", makeIcon("b1.png")));
		card.add(new Card(2, 2, "blue", makeIcon("b2.png")));
		card.add(new Card(3, 3, "blue", makeIcon("b3.png")));
		card.add(new Card(4, 4, "blue", makeIcon("b4.png")));
		card.add(new Card(5, 5, "blue", makeIcon("b5.png")));
		card.add(new Card(6, 6, "blue", makeIcon("b6.png")));
		card.add(new Card(7, 7, "blue", makeIcon("b7.png")));
		card.add(new Card(8, 8, "blue", makeIcon("b8.png")));
		card.add(new Card(9, 9, "blue", makeIcon("b9.png")));
		card.add(new Card(10, 20, "blue", makeIcon("br.png")));
		card.add(new Card(11, 20, "blue", makeIcon("bs.png")));
		card.add(new Card(12, 20, "blue", makeIcon("bd2.png")));
		card.add(new Card(0, 0, "blue", makeIcon("b0.png")));
		card.add(new Card(13, 50, "wild", makeIcon("w.png")));
		card.add(new Card(13, 50, "wild", makeIcon("w.png")));
		card.add(new Card(13, 50, "wild", makeIcon("w.png")));
		card.add(new Card(13, 50, "wild", makeIcon("w.png")));
		card.add(new Card(14, 50, "wild", makeIcon("w4.png")));
		card.add(new Card(14, 50, "wild", makeIcon("w4.png")));
		card.add(new Card(14, 50, "wild", makeIcon("w4.png")));
		card.add(new Card(14, 50, "wild", makeIcon("w4.png")));

		// shuffle method from class collection
		Collections.shuffle(card);
	}

	/**
	 * Constructor that takes a list
	 * 
	 * @param card
	 */
	public Deck(Stack<Card> card)
	{
		this.card = card;
	}

	public void addToDeck(Stack<Card> discardPile)
	{
		for (Card varCard : discardPile)
		{
			card.add(varCard);
			Collections.shuffle(card);
		}
	}

	/**
	 * This method gets the icon string from the list of cards at the specified
	 * index
	 * 
	 * @param index
	 * @return icon
	 * @see Card
	 * @see Uno_UI
	 */
	public ImageIcon getCardIconAt(int index)
	{
		// Card iconHolder = card.get(index);
		// String gotcha = iconHolder.getIcon();
		return card.get(index).getIcon();
	}

	public Card remove()
	{
		return card.pop();
	}

	public void setDeck(Stack<Card> card)
	{
		this.card = card;
	}

	public int deckSize()
	{
		return card.size();
	}

	public static ImageIcon makeIcon(String path)
	{
		ImageIcon imageIcon = new ImageIcon(Toolkit.getDefaultToolkit()
				.getImage(Deck.class.getResource("/images/" + path)));
		return imageIcon;
	}

	@Override
	public String toString()
	{
		return "Deck [" + card + "]";
	}

}
